42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

什麼是 Cross-Origin Resource Sharing (CORS)?

什麼是 Cross-Origin Resource Sharing (CORS)?

JS註冊組|JavaScript基本語法|JavaScript&jQuery網站互動設計程式進化之道

JS註冊組|JavaScript基本語法|JavaScript&jQuery網站互動設計程式進化之道

OOP - 4 抽象類別與介面 (1)

OOP - 4 抽象類別與介面 (1)


Comments